var StaticVar_startDate = null;
var StaticVar_endDate = null;

Ext.define('Ext.calendar.data.Events', {
	statics : {
		loadDataList : function(eventStore, type) {
			type = type || "mapping";

			StaticVar_endDate.setHours(23);
			StaticVar_endDate.setMinutes(59);
			StaticVar_endDate.setSeconds(59);

			Request.request('oa-Schedule-queryListByDate', {
						startDate : StaticVar_startDate,
						endDate : StaticVar_endDate
					}, function(resultList) {
						var dataList = [];
						for (var i = 0; i < resultList.length; i++) {
							var result = resultList[i];
							var EventId = Ext.calendar.data.EventMappings.EventId[type];
							var CalendarId = Ext.calendar.data.EventMappings.CalendarId[type];
							var IsAllDay = Ext.calendar.data.EventMappings.IsAllDay[type];
							var StartDate = Ext.calendar.data.EventMappings.StartDate[type];
							var EndDate = Ext.calendar.data.EventMappings.EndDate[type];
							var Title = Ext.calendar.data.EventMappings.Title[type];
							var isOk = Ext.calendar.data.EventMappings.isOk[type];
							var level = Ext.calendar.data.EventMappings.level[type];
							var participants = Ext.calendar.data.EventMappings.participants[type];
var userId = Ext.calendar.data.EventMappings.userId[type];
							
							var obj = {};
							obj[EventId] = result.id;
							obj[CalendarId] = result.ctype;
							obj[IsAllDay] = result.allDay;
							obj[StartDate] = new Date(result.start);
							obj[EndDate] = new Date(result.end);
							obj[Title] = result.content;
							obj[isOk] = result.isOk;
							obj[level] = result.level;
							obj[participants] = result.participants;
							obj[userId] = result.userId;
							if (result.level == '1') {
								obj.flag_green = true;
							} else if (result.level == '2') {
								obj.flag_blue = true;
							} else if (result.level == '3') {
								obj.flag_yellow = true;
							} else if (result.level == '4') {
								obj.flag_red = true;
							}
							dataList.push(obj);
						}
						eventStore.loadData(dataList);
					});
		},

		getData : function() {

			return {
				"evts" : []
				// Ext.calendar.data.Events.getDataList()
				// [{
				// "id" : "ddd",
				// "ctype" : 1,
				// "content" : "这个是我的日程安排",
				// "start" : new Date(),
				// "end" : new Date(),
				// "notes" : "Have fun"
				// }]
			}
		},
		toData : function(data) {
			for (var p in data) {
				var mapping = Ext.calendar.data.EventMappings[p];
				if (mapping) {
					data[mapping.mapping] = data[p];
				}
			}
			return data;
		}
	}
});
